﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IndexDefinitionRepository.cs" company="DST Nexdox">
//   Copyright (c) DST Nexdox. All rights reserved.
// </copyright>
// <summary>
//   Defines the IndexDefinitionRepository type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DocProcessingRepository.Repositories
{
  using System;
  using System.Collections.Generic;
  using System.Data.Entity;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using DocProcessingRepository.Contexts;
  using DocProcessingRepository.Interfaces;
  using EFRepository;
  using Entities;

  public class IndexDefinitionRepository : BaseEfRepository<IndexDefinition>, IIndexDefinitionRepository
  {
    public IndexDefinitionRepository(String connectionString)
      : base(new IdentityDb(connectionString))
    {
    }

    public void UpdateMailSortSetting(Int32 mediaDefinitionId, Int32? mailSortSettingId)
    {
      if (mailSortSettingId.HasValue && mailSortSettingId <= 0)
      {
        throw new ArgumentException("mailSortSettingId cannot be negative or zero");
      }

      String mailSortSettingIdIntParameter = mailSortSettingId.HasValue ? mailSortSettingId.ToString() : "NULL";

      this.ExecuteStoredProcedure(
        String.Format("UpdateMailSortSettingForMediaDefinition {0}, {1}", mediaDefinitionId, mailSortSettingIdIntParameter));
    }
  }
}
